package com.sky.chapter3.lock;

/**
 * @author : wushikai
 * <p>
 * date : 2022-07-04
 */
public class ReEntryLockDemo {

    private synchronized void m1() {
        System.out.println("-----m1");
        m2();
    }

    private synchronized void m2() {
        System.out.println("-----m2");
        m3();
    }

    private synchronized void m3() {
        System.out.println("-----m3");
    }

    public static void main(String[] args) {
        ReEntryLockDemo reEntryLockDemo = new ReEntryLockDemo();

        reEntryLockDemo.m1();
    }

    //相当于


    public static void test(String[] args) {
        final Object objectLockA = new Object();

        new Thread(() -> {
            synchronized (objectLockA) {
                System.out.println("-----外层调用");
                synchronized (objectLockA) {
                    System.out.println("-----中层调用");
                    synchronized (objectLockA) {
                        System.out.println("-----内层调用");
                    }
                }
            }
        }, "a").start();
    }


}
